home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
snpd9611.zip
/
ANSIFLEN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-11-24
|
1KB
|
55 lines
.I 0 2
/* +++Date last modified: 09-Nov-1996 */
.I 9 37
#if defined(__cplusplus) && __cplusplus /* C++ version follows */
#include <fstream.h>
long flength(char *fname)
{
long length = -1L;
ifstream ifs;
ifs.open(fname, ios::binary);
if (ifs)
{
ifs.seekg(0L, ios::end) ;
length = ifs.tellg() ;
}
return length;
}
#else /* Straight C version follows */
long flength(char *fname)
{
long length = -1L;
FILE *fptr;
fptr = fopen(fname, "rb");
if(fptr != NULL)
{
fseek(fptr, 0L, SEEK_END);
length = ftell(fptr);
fclose(fptr);
}
return length;
}
#endif /* C++ */
.D 10 15
.I 36 10
char *ptr;
long len;
while (--argc)
{
len = flength(ptr = *(++argv));
if (-1L == len)
printf("\nUnable to get length of %s\n", ptr);
else printf("\nLength of %s = %ld\n", ptr, len);
}
.D 37 1